<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/27 0027
 * Time: 13:06
 */

namespace common\models;


use yii\web\ForbiddenHttpException;
use Yii;
use yii\web\ViewAction;

class Permissin
{
    public function checkPermission(){


        $this->getPermiss();
        $con = Yii::$app->controller->id;
        $action = Yii::$app->controller->action->id;
        $url = $con.'/'.$action;
        if ( Yii::$app->user->identity->getUsername() == Adminuser::SpuerAD){
            return true;
        }
        $list = $this->getPermiss();

        if (!in_array($url,$list)){
            throw new ForbiddenHttpException('你无该权限操作');
        }

    }
    public function getPermiss(){

        $assignment = AuthAssignment::find()->select(['item_name'])->where(['user_id'=>Yii::$app->user->identity->id])->all();
        $list = [];
        foreach ($assignment as $k =>$v){
            $child = AuthItemChild::find(['child'])->where(['parent'=>$v->item_name])->all();
            foreach ($child as $kk => $vv){
                $list [] = $vv->child;
            }
        }
        return $list;
    }

}